/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-10-11     RT-Thread    first version
 */

#include <rthw.h>
#include <rtthread.h>
#include "board.h"


#define DBG_TAG "main"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>


void rt_hw_board_init(void);
void rt_application_init(void);

int main(void)
{
    rt_hw_interrupt_disable();

    /* board level initialization
     * NOTE: please initialize heap inside board initialization.
     */
    rt_hw_board_init();

    /* timer system initialization */
    rt_system_timer_init();

    /* scheduler system initialization */
    rt_system_scheduler_init();

    /* create init_thread */
    rt_application_init();

    /* timer thread initialization */
    rt_system_timer_thread_init();

    /* idle thread initialization */
    rt_thread_idle_init();

    /* start scheduler */
    rt_system_scheduler_start();

    /* never reach here */
    return 0;

}


static void init_entry(void *parameter)
{

    /* Board underlying hardware initialization */
#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif

    /* show RT-Thread version */
    rt_show_version();

#ifdef RT_USING_COMPONENTS_INIT
    /* RT-Thread components initialization */
    rt_components_init();
#endif

    int mqtt_demo(int argc, void *argv[]);
    mqtt_demo(0,NULL);


    while (1)
    {
        rt_thread_mdelay(500);
//        rt_hw_debug_led(0);
//        rt_thread_mdelay(500);
//        rt_hw_debug_led(1);
//        LOG_D("Hello Khons!");
    }

}

void rt_application_init(void)
{
    rt_thread_t tid;

    tid = rt_thread_create("init", init_entry, RT_NULL,4096,10,20);
    RT_ASSERT(tid != RT_NULL);
    rt_thread_startup(tid);
}



